<template>
    <div class="identity">
        <el-form :inline="true" :model="formInline">
            <el-form-item label="地区">
                <el-input v-model="formInline.area" placeholder="地区"></el-input>
            </el-form-item>
            <el-form-item label="昵称">
                <el-input v-model="formInline.nickname" placeholder="昵称"></el-input>
            </el-form-item>
            <el-form-item label="手机号码">
                <el-input v-model="formInline.phone" placeholder="手机号码"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="search">搜索</el-button>
                <el-button type="primary" @click="reset">重置</el-button>
            </el-form-item>
        </el-form>
        <el-table
            :header-cell-style="{color:'#555555'}"
            class="black"
            :data="tableData"
            max-height="650"
            stripe
            border
            style="width: 100%">
            <el-table-column
                prop="id"
                label="用户ID"
                align="center">
            </el-table-column>
            <el-table-column
                prop="username"
                label="账号"
                align="center">
            </el-table-column>
            <el-table-column
                prop="phone"
                label="手机号码"
                align="center">
            </el-table-column>
            <el-table-column
                prop="area"
                label="所在区域"
                align="center">
            </el-table-column>
            <el-table-column
                prop="datingArea"
                label="约会范围"
                align="center">
            </el-table-column>
            <el-table-column
                prop="nickname"
                label="昵称"
                align="center">
            </el-table-column>
            <el-table-column
                prop="identity"
                label="认证"
                align="center">
            </el-table-column>
            <el-table-column
                prop="wallet"
                label="历史收入"
                align="center">
            </el-table-column>
            <el-table-column
                prop="loginTime"
                label="最近登录"
                align="center">
            </el-table-column>
            <el-table-column
                prop="registerTime"
                label="注册时间"
                align="center">
            </el-table-column>
            <el-table-column
                prop="identityPhoto"
                v-if="show = false">
            </el-table-column>
            <el-table-column label="操作" align="center" width="254">
                <template slot-scope="scope">
                <el-button @click="onCheckClick(scope.row)" size="small">查看</el-button>
                <el-button @click="onPassClick(scope.row)" size="small">通过</el-button>
                <el-button @click="onNoPassClick(scope.row)" size="small">不通过</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="footer-page">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="page"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="page_size"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total_page">
            </el-pagination>
        </div>
        <el-dialog
        :visible.sync="dialogVisible">
            <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: 'identity',
    data () {
        return {
            page: 1,
            page_size: 10,
            total_page: 0,
            formInline: {
                area: '',
                nickname: '',
                phone: ''
            },
            params: {
                page: 1,
                limit: 10,
                order: 'asc'
            },
            tableData: [],
            state_id: '',
            identity: 0,
            dialogVisible: false,
            dialogImageUrl: ''
        }
    },
    created () {

    },
    mounted () {
        this.getList({ 'params': this.params })
    },
    methods: {
        getList (data) {
            this.tableData = []
            this.$api.user.getIdentityList(data, res => {
                if (res.code === 200) {
                    let data = res.page.list || []
                    for (let i = 0; i < data.length; i++) {
                        this.tableData.push(data[i])
                    }
                    this.total_page = res.page.totalCount
                    this.page_size = res.page.pageSize
                    this.page = res.page.currPage
                }
            })
        },
        search () {
            this.page = 1
            this.params['area'] = this.formInline.area
            this.params['nickname'] = this.formInline.nickname
            this.params['phone'] = this.formInline.phone
            this.getList({ 'params': this.params })
        },
        reset () {
            this.page = 1
            this.formInline.area = ''
            this.formInline.nickname = ''
            this.formInline.phone = ''
            this.params['area'] = this.formInline.area
            this.params['nickname'] = this.formInline.nickname
            this.params['phone'] = this.formInline.phone
            this.getList({ 'params': this.params })
        },
        onCheckClick (row) {
            this.dialogImageUrl = row.identityPhoto
            this.dialogVisible = true
        },
        onPassClick (row) {
            this.state_id = row.id
            this.identity = 2
            this.onSureClick()
        },
        onNoPassClick (row) {
            this.state_id = row.id
            this.identity = 0
            this.onSureClick()
        },
        onSureClick () {
            this.$api.user.editIdentity({'id': this.state_id, 'identity': this.identity}, res => {
                if (res.code === 200) {
                    this.$message.success(res.msg)
                    this.reset()
                } else {
                    this.$message.error(res.msg)
                }
            })
        },
        handleSizeChange (val) {
            this.page_size = val
            this.params.limit = val
            this.params.page = this.page
            this.getList({'params': this.params})
        },
        handleCurrentChange (val) {
            this.page = val
            this.params.page = val
            this.params.limit = this.page_size
            this.getList({ 'params': this.params })
        }
    }
}
</script>

<style lang="less" scoped>
    .identity {
        position: relative;
        width: 100%;
        height: 100%;
        .margin-bottom-12 {
            margin-bottom: 10px;
        }
        .el-row {
            margin-bottom: 20px;
            &:last-child {
                margin-bottom: 0;
            }
        }
        .el-col {
            border-radius: 4px;
        }
        .grid-content {
            position: relative;
            height: 40px;
        }
        .grid-padding {
            /* padding-left: 20px; */
            padding-right: 20px;
        }
        .grid-title {
            float: left;
            width: 72px;
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            color: #333;
            text-align: center;
        }
        .grid-input {
            float: left;
            width: 130px;
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            color: #333;
            text-align: center;
        }
        .row-bg {
            padding: 10px 0;
            background-color: #f9fafc;
        }
        .footer-page {
            width: 540px;
            margin: 0 auto;
            padding-top: 20px;
        }
    }
</style>
